<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <title>Example</title>
    <link rel="stylesheet" href="./css/common.css">
    <link rel="stylesheet" href="./css/type.css">
    <link rel="stylesheet" href="./plugins/swiper/swiper-bundle.min.css">
    <script src="./js/vue.min.js"></script>
    <link rel="shortcut icon" href="./favicon.png" type="image/x-icon">
</head>
<style>
    .search {
        width: 500px;
        margin: 0 auto;
    }
    @media screen and (max-width: 768px) {
        .search {
            display: none;
        }
    }
</style>
<body>
    <div id="app">
        <m-Header></m-Header>

        <div class="search">
            <m-Search :init-text="keywords"></m-Search>
        </div>

        <main>
            <div class="wrapper">
                <div class="games">
                    <div class="games-title">
                        <img src="./imgs/search_orage.svg" alt="search" width="20">
                        <span>Search Result</span>
                    </div>
                    <div class="games-content">
                        <a :href="handleToDetail(game.gameId)" class="games-wrapper" v-for="game in list">
                            <div class="games-wrapper-logo">
                                <img class="games-wrapper-logo_icon" :src="game.gameLogo" :alt="game.gameName">
                            </div>
                            <span class="games-wrapper-name">{{game.gameName}}</span>
                        </a>
                    </div>
                </div>
            </div>
            <m-Hot></m-Hot>
        </main>

        <m-Footer></m-Footer>
    </div>
</body>
<script src="./main.js"></script>
<script src="./plugins/swiper/swiper-bundle.min.js"></script>
<script type="module">
    import { Header, Footer, Search } from './components/index.js'
    import Hot from './components/hot.js'
    var vm = new Vue({
        el: '#app',
        components: {
            mHeader: Header,
            mFooter: Footer,
            mHot: Hot,
            mSearch: Search
        },
        data() {
            return {
                keywords: '',
                list: []
            }
        },
        created() {
            this.keywords = getQueryVariable('keywords') || 'Search'
            document.title = this.keywords
            this.handleGetSearchResult()
        },
        mounted() {
        },
        methods: {
            handleToDetail(id) {
                return `./detail.html?id=${id}`
            },
            handleGetSearchResult() {
                fetch('https://www.migame.vip/gamefront/gameList/search', {
                    headers: {
                        'Content-Type': 'application/json; charset=utf-8'
                    },
                    method: 'post',
                    body: JSON.stringify({
                        gameName: this.keywords,
                        isTop: -1,
                        limit: 20,
                        page: 1,
                    })
                })
                    .then(res => res.json())
                    .then(res => {
                        this.list = res.data
                    })
                    .catch(function (error) {
                        // 请求失败后执行的回调函数
                        console.log('error:', error)
                    })
            },
        }
    })
</script>

</html>